package com.xb.cloud.merchantapi.adapter;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.xb.cloud.gateway.client.Adapter;
import com.xb.cloud.gateway.client.AdapterContext;
import com.xb.cloud.gateway.client.RtnInfo;
import com.xb.cloud.merchantapi.product.service.FinanceApiService;
import com.xb.cloud.product.merchant.service.client.bo.EndMerchantUserBo;

/**
 * 
 * @ClassName: FinanceApiAdapter
 * @Description:商家资金管理
 * @author: 鲜备科技
 * @date: 2018年3月9日 上午11:00:42
 * 
 * @Copyright: 2018 www.xianbeitech.com Inc. All rights reserved.
 *
 */

@Component
public class FinanceApiAdapter extends Adapter {
	private final Logger logger = LoggerFactory.getLogger(FinanceApiAdapter.class);

	@Resource
	FinanceApiService financeApiService;

	/**
	 * 
	 * <p>
	 * Title: execute
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @param urlPath
	 * @param isLogined
	 * @param bizInfo
	 * @param context
	 * @return
	 * @see com.xb.cloud.gateway.client.Adapter#execute(java.lang.String,
	 *      java.lang.Boolean, java.util.Map,
	 *      com.xb.cloud.gateway.client.AdapterContext)
	 */
	public RtnInfo execute(String urlPath, Boolean isLogined, Map<String, String> bizInfo, AdapterContext context) {
		long time = System.currentTimeMillis();

		RtnInfo rtnInfo = null;
		long companyId = context.getCompanyId();
		Long endMerchantUserId = context.getCurrentMerchantUserId();

		if ("/h5/merchant/finance/getMerchantFinaceInfo".equalsIgnoreCase(urlPath)) {
			EndMerchantUserBo merchantUserBo = new EndMerchantUserBo();
			merchantUserBo.setCompanyId(companyId);
			merchantUserBo.setId(endMerchantUserId);
			return financeApiService.getMerchantFinaceInfo(merchantUserBo);
		}

		logger.debug("执行时间：{}", System.currentTimeMillis() - time);
		return rtnInfo;
	}

	@Override
	public String getUrlMappingPath() {
		return "/h5/merchant/finance/**";
	}

	@Override
	public boolean isCheckUserToken() {
		return true;
	}
}
